<?php 
defined('IN_TS') or die('Access Denied.'); 

function newduty(){
	global $db;
	//最新服务

	$arrDutys = aac('duty')->findAll('duty',
		'status>-1'
	,'addtime desc',null,5);

	if (count($arrDutys) > 0) {
		$groupids = array_column($arrDutys, "groupid");
		$groups = aac('group')->getGroups($groupids);

		$userids = array_column($arrDutys, "userid");
		$users = aac('user')->getUsers($userids);

		$dutyCates = aac("duty")->getDutyCates();
	}

	
	foreach($arrDutys as $key=>$item){

		    $arrDuty[] = $item;
			$arrDuty[$key]['user'] = $users[$item["userid"]];
			$strGroup =  $groups[$item['groupid']]; 
			$arrDuty[$key]['address'] = $strGroup['groupname'];
			$arrDuty[$key]['job'] = cututf8($item['job'],0,40,true);
			if($item['image']){
				$arrDuty[$key]['image'] = explode(',',$item['image']);
			}
			//服务类型
			$arrCate= $dutyCates[$item["cateid"]];
			$arrDuty[$key]['cate'] = $arrCate['catename'];
		   }


	include template('newduty','newduty');
	
}

function newduty_css(){

	echo '<link href="'.SITE_URL.'plugins/home/newduty/style.css" rel="stylesheet" type="text/css" />';

}

addAction('home_index_left','newduty');
addAction('pub_header_top','newduty_css');